#pragma once
#include<iostream>
using namespace std;
namespace zkf
{
	class string
	{
		typedef char* iterator;
		typedef const char* const_iterator;
	public:
		/*string()
			:_s(nullptr)
			, _size(0)
			, _capacity(0)
		{
		}*/
		string(const char* s="")
		{
			_size=strlen(s);
			_capacity = _size;
			_s = new char[_capacity + 1];
			strcpy(_s, s);
		}
		void swap(string& s)
		{
			std::swap(_s, s._s);
			std::swap(_size, s._size);
			std::swap(_capacity, s._capacity);
		}
		string(const string& s)
		{
			string tmp(s._s);
			swap(tmp);
		}
		string& operator=(string s)
		{
			swap(s);
			return *this;
		}
		iterator begin()
		{
			return _s;
		}
		iterator end()
		{
			return _s+_size;
		}
		const_iterator begin()const 
		{
			return _s;
		}
		const_iterator end()const
		{
			return _s+_size;
		}
		char* tou()const
		{
			return _s;
		}
		size_t size()const
		{
			return _size;
		}
		size_t capacity()const
		{
			return _capacity;
		}
		char operator[](size_t i)
		{
			return _s[i];
		}
		char operator[](size_t i)const
		{
			return _s[i];
		}
		bool empty()const
		{
			return _size == 0;
		}
		void clear()
		{
			_s[0] = '\0';
			_size = 0;
		}
		void reserve(size_t n);
		void push_back(char c);
		void append(const char* s);
		string& operator+=(char c);
		string& operator+=(const char* s);
		void insert(size_t pos, char c);
		void insert(size_t pos, const char* s);
		void erase(size_t pos,size_t len=npos);
		void pop_back();
		size_t find(char c,size_t pos);
		size_t find(const char* s,size_t pos);
		string substr(size_t pos=0,size_t len=npos);
		~string()
		{
			delete[] _s;
			_s = nullptr;
			_size = 0;
			_capacity = 0;
		}
	private:
		char* _s=nullptr;
		size_t _size=0;
		size_t _capacity=0;
		static const size_t npos;
	};
	bool operator<(const string& s1, const string& s2);
	bool operator==(const string& s1, const string& s2);
	bool operator<=(const string& s1, const string& s2);
	bool operator>(const string& s1, const string& s2);
	bool operator>=(const string& s1, const string& s2);
	bool operator!=(const string& s1, const string& s2);
	ostream& operator<<(ostream& out, const string& s);
	istream& operator>>(istream& in, string& s);
}
